<?php
/**
 * 图百科管理
 * 
 * @author  Lee<a605333742@gmail.com>
 * @time    2016-07-31
 */
namespace Admin\Controller;

class WikiController extends CommonController{
    /*
     * 构造函数
     * @return #
     */
    public function _initialize() {
        parent::_initialize();
        $this->db   =new \Model\WikiModel();
    }
    
    /*
     * 涂百科列表
     * 
     * @return #
     */
    public function index(){
        $map        =$this->_search("Wiki");
        $sortBy     ='top';
        $sort       =desc;
        $wikiList   =$this->_list($this->db,$map,$sortBy,$sort);
        $this->assign("wikiList",$wikiList);
        show_bug($wikiList);exit;
        $this->display();
    }
    
    /*
     * 显示编辑涂百科
     * 
     * @return #
     */
    public function show(){
        if(I("request.id")){
            $wikiInfo   =$this->db->find(I("request.id"));
            $this->assign("wikiInfo",$wikiInfo);
        }
        $this->display();
    }
    
    /*
     * 编辑涂百科
     * 
     * @return #
     */
    public function edit(){
        if(I("request.id")){
            $map['id']      =I("request.id","","int");
        }
        if(I("request.name")){
            $map['name']    =I("request.name","","trim");
        }else{
            $this->error("名称不能为空");
        }
        /*
        if(I("request.icon")){
            $map['icon']=I("request.icon","","trim");
        }
        */
        
        if(I("request.type")){
            $map['type']    =I("request.type","","trim");
        }
        if(I("request.typeNo")){
            $map['typeNo']  =I("request.typeNo","","trim");
        }
        if(I("company")){
            $map['company'] =I("request.company","","trim");
        }
        if(I("website")){
            $map['website'] =I("request.website","","trim");
        }
        if(I("request.price")){
            $map['price']   =I("request.price","","trim");
        }
        if(I("request.description")){
            $map['description'] =I("request.description","","trim");
        }
        if($this->db->edit($map)){
            $this->success("涂百科编辑成功");
        }else{
            $this->error("涂百科编辑失败");
        }
    }
    
    /*
     * 删除、批量删除涂百科
     * 
     * @return #
     */
    public function del(){
        $map['id']      =I("request.id");
        if($this->db->edits($map)){            
            $this->success("删除成功",U("index"));
        }else{
            $this->error("删除失败",U("index"));
        }
    }
   
}